﻿using System.Collections.Generic;
using System.Linq;

namespace OnlineSupermarket
{
    public sealed partial class OnlineSupermarket
    {
        public record Receipt(IReadOnlyDictionary<GoodsInfo, int> GoodsInfoAndWeights)
        {
            public decimal TotalPrice => this.GoodsInfoAndWeights.Sum(
                (infoAndWeight) => infoAndWeight.Value * infoAndWeight.Key.Price);

            public decimal FreightAndPackingFee
            {
                get
                {
                    var totalWeight = this.GoodsInfoAndWeights.Sum(
                        (infoAndCount) => infoAndCount.Value);

                    return totalWeight switch {
                        < 5 => 6.5m,
                        >= 5 and < 20 => 13m,
                        _ => 13m + totalWeight * .2m
                    };
                }
            }
        }
    }
}